<div class="panel panel-default">
	<div class="panel-heading newsfeed">
		<p>Respond to Your <?php echo count($friendrequest);?> Friend Requests</p>
	</div>
	<ul class="list-group">
	<?php if(!empty($friendrequest)):?>
		<?php foreach($friendrequest as $friend):?>
		<li class="list-group-item">
			<div class="row">
				<div class="col-md-2">
					<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo (empty($friend['photo'])? DEFAULT_IMG : $friend['photo']) ; ?>" class="" width="75" height="75">
				</div>
				<div class="col-md-5">
					<h4><?=$friend['firstname'].' '.$friend['lastname']?></h4>
				</div>
				<div class="col-md-5">
					<button type="button" class="btn btn-primary" id="confirm_friend<?=$friend['userid']?>" onclick="friendaction('<?php echo $friend['userid'];?>','confirm')"><span class="glyphicon glyphicon-ok"></span> Confirm</button>
					<button type="button" class="btn btn-default" id="delete_friend<?=$friend['userid']?>" onclick="friendaction('<?php echo $friend['userid'];?>','delete')"><span class="glyphicon glyphicon-remove"></span> Delete Request</button>	
				</div>
			</div>
		</li>
		<?php endforeach; ?>
		<?php else: ?>
		<li class="list-group-item">
		<p>No Request Yet</p>
		</li>
		<?php endif; ?>
	</ul>
</div>   
<script>
function friendaction(userid,action)
{
	var dataString = "userid=" + userid + "&action=" + action ;
	$.ajax({  
        type: "POST",  
        url: "<?php echo base_url('ajax/friend_request')?>",  
        data: dataString,
		cache: false,
        beforeSend: function() 
        {
			if(action=='add')
			{
				$('#add_friend'+userid).prop('disabled', true);
			}
			else if(action=='cancel')
			{
				$('#add_friend'+userid).prop('disabled', false);
				$('#add_friend'+userid).html('<span class="glyphicon glyphicon-user"></span> Add Friend');	
			}
			else if(action=='confirm')
			{
				$('#confirm_friend'+userid).prop('disabled', false);
			}
        },  
        success: function(response)
        {
            if(response == "requested")
			{
				$('#add_friend'+userid).prop('disabled', true);
				$('#add_friend'+userid).html('<span class="glyphicon glyphicon-user"></span> Friend Request Sent');
				$('#cancel_friend'+userid).show();
			}
			else if(response == "cancel")
			{
				$('#cancel_friend'+userid).hide();
			}
			else if(response == "confirm")
			{
				$('#confirm_friend'+userid).prop('disabled', true);
				$('#confirm_friend'+userid).html('<span class="glyphicon glyphicon-user"></span> Friend');
				
			}
        }
    });
}
</script>